//package com.sf.fy.uav.applet.temporary;
//
//import cn.hutool.db.sql.Order;
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.sf.fy.uav.common.enums.ActivityProductTypeEnum;
//import com.sf.fy.uav.order.entity.OrderInfo;
//import com.sf.fy.uav.order.mapper.OrderInfoMapper;
//import com.sf.fy.uav.user.entity.CityReceivingInformation;
//import com.sf.fy.uav.user.mapper.CityReceivingInformationMapper;
//import jakarta.annotation.PostConstruct;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.http.client.SimpleClientHttpRequestFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.client.RestTemplate;
//
//import java.net.InetSocketAddress;
//import java.net.Proxy;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//
//@Component
//public class TemporaryBatchControllerTest {
//    @Value("${new-proxy-url:IE-UOCS-CORE-3adm832e.lbsit.sfcloud.local}")
//    private String newProxyUrl;
//
//
//    @Autowired
//    private OrderInfoMapper orderInfoMapper;
//
//
//    @PostConstruct
//    public void dealAddress() {
//        try {
//            LambdaQueryWrapper<OrderInfo> orderInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//            orderInfoLambdaQueryWrapper.isNull(OrderInfo::getOrderType).isNotNull(OrderInfo::getSenderLon).isNotNull(OrderInfo::getSenderLat).isNotNull(OrderInfo::getReceiverLon).isNotNull(OrderInfo::getReceiverLat); //
//            List<OrderInfo> orderInfoList = orderInfoMapper.selectList(orderInfoLambdaQueryWrapper);
//
//            orderInfoList.forEach(orderInfo -> {
//                String location = orderInfo.getSenderLat() + "," + orderInfo.getSenderLon(); // 经度,纬度
//                Map<String, String> params = new HashMap<>(2);
//                params.put("param1", "R7EBZ-OZ4EW-MJPRB-YJF6A-YXMYH-3DF2Y");
//                params.put("param2", location);
//                Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(newProxyUrl, 80));
//                SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
//                requestFactory.setProxy(proxy);
//                RestTemplate restTemplate = new RestTemplate(requestFactory);
//                String forObject = restTemplate.getForObject("https://apis.map.qq.com/ws/geocoder/v1/?location={param2}&key={param1}", String.class, params);
//                System.out.println(forObject);
//                if (JSONObject.parseObject(forObject).getInteger("status") == 0) {
//                    String fromProvince = JSONObject.parseObject(forObject).getJSONObject("result").getJSONObject("address_component").getString("province");
//                    String fromCity = JSONObject.parseObject(forObject).getJSONObject("result").getJSONObject("address_component").getString("city");
//
//
//                    location = orderInfo.getReceiverLat() + "," + orderInfo.getReceiverLon(); // 经度,纬度
//                    params = new HashMap<>(2);
//                    params.put("param1", "R7EBZ-OZ4EW-MJPRB-YJF6A-YXMYH-3DF2Y");
//                    params.put("param2", location);
//                    requestFactory.setProxy(proxy);
//                    forObject = restTemplate.getForObject("https://apis.map.qq.com/ws/geocoder/v1/?location={param2}&key={param1}", String.class, params);
//                    System.out.println(forObject);
//
//
//                    String toProvince = JSONObject.parseObject(forObject).getJSONObject("result").getJSONObject("address_component").getString("province");
//                    String toCity = JSONObject.parseObject(forObject).getJSONObject("result").getJSONObject("address_component").getString("city");
//                    if (fromProvince.equals(toProvince) && fromCity.equals(toCity)) {
//                        orderInfo.setOrderType(ActivityProductTypeEnum.LOCAL.getCode());
//                    } else {
//                        orderInfo.setOrderType(ActivityProductTypeEnum.CROSS_REGION.getCode());
//                    }
//                    orderInfoMapper.updateById(orderInfo);
//                }
//
//            });
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//}
